home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / General / MM3Tp.sea Folder / Made by Marksman / Sources / u / commonMM_Demo.p < prev    next >
Text File  |  1994-01-16  |  8KB  |  287 lines

  1. unit CommonMM_Demo;
  2. {  commonMM_Demo                         Common }
  3. {  Copyright © 1994 George R. Cossey }
  4.  
  5.     File name:  commonMM_Demo
  6.     Function:  Common variables for program specific code. 
  7.     History: 1/16/94 Original by George Cossey
  8.  
  9.    }
  10.  
  11.  
  12. interface
  13.  
  14. uses
  15.     Printing, Folders, Sound,mmCommonMM_Demo;
  16.  
  17. { ======================================================= }
  18. { ======================================================= }
  19.  
  20. { NOTE : FormatRevision MUST be first in the record, and always a short }
  21. type
  22.   PrefsHRec = ^PrefsPRec;                 {Handle definition}
  23.   PrefsPRec = ^PrefsRec;                  {Pointer definition}
  24. PrefsRec = record                    { Preferences Record definition }
  25.     { ALWAYS KEEP FormatRevision AS THE FIRST ELEMENT IN THIS RECORD }
  26.     FormatRevision:integer;            { FIRST ALWAYS, Change each time the format changes }
  27.     theWindowLocRec:WindowLocRec;    { For saving window positions }
  28.     { Add other preference variable definitions after this line }
  29.  
  30.     end;
  31.  
  32. { ======================================================= }
  33.  
  34. const
  35.     PrefsCreator =    'xxxx';            { Creator, this has to be the same as your App }
  36.     PrefsType    =    'Pref';            { Type, this has to match the type in your BNDL }
  37.     PrefsFormatRevision     = 1;            { Change each time the format changes }
  38.  
  39. procedure U_InitPreferences;
  40. procedure U_GetPrefParams(var PrefCreator,PrefType:OSType;var thePrefsFilename:Str255;var PrefsRecSize:longint;var thePrefsFormatRevision:integer);
  41. procedure U_ReadPrefsPrivate(PrefsRefNum:integer);
  42. procedure U_GetPreferences(thePrefsH:Handle);
  43. procedure U_SetPreferences(thePrefsH:Handle);
  44.  
  45. procedure Close_The_Input_File;
  46. procedure Close_The_Output_File;
  47. procedure Open_The_File;
  48. procedure Select_Volume;
  49. procedure Save_The_File;
  50. procedure Print_The_Data;
  51.  
  52. { ======================================================= }
  53. { ======================================================= }
  54.  
  55. implementation
  56.  
  57. { ======================================================= }
  58. { ======================================================= }
  59.  
  60. { Routine: U_InitPreferences }
  61. { Purpose: Set the default preferences }
  62.  
  63. procedure U_InitPreferences;
  64.  
  65.  
  66. begin
  67. end;
  68.  
  69. { ======================================================= }
  70.  
  71. { Routine: U_GetPrefParams }
  72. { Purpose: Get the preferences Parameters }
  73.  
  74. procedure U_GetPrefParams(var PrefCreator,PrefType:OSType;var thePrefsFilename:Str255;var PrefsRecSize:longint;var thePrefsFormatRevision:integer);
  75.  
  76.  
  77. begin
  78. PrefCreator := PrefsCreator;
  79. PrefType := PrefsType;
  80. thePrefsFilename := 'My Prefs';
  81. PrefsRecSize := sizeof(PrefsRec);
  82. thePrefsFormatRevision := PrefsFormatRevision;
  83. end;
  84.  
  85. { ======================================================= }
  86.  
  87. { Routine: U_ReadPrefsPrivate }
  88. { Purpose: Read the prefs ourselves }
  89.  
  90. procedure U_ReadPrefsPrivate(PrefsRefNum:integer);
  91.  
  92.  
  93. begin
  94. end;
  95.  
  96. { ======================================================= }
  97.  
  98. { Routine: U_GetPreferences }
  99. { Purpose: Get the preferences from the Prefs record already read in }
  100.  
  101. procedure U_GetPreferences(thePrefsH:Handle);
  102. var
  103.  thePrefs:PrefsHRec;
  104.  
  105.  
  106. begin
  107. thePrefs := PrefsHRec(thePrefsH);
  108. theWindowLocRec := thePrefs^^.theWindowLocRec;    { Get the window location data }
  109.  
  110. { Use the form:   xxxx := thePrefs^^.xxxx;    }
  111. end;
  112.  
  113. { ======================================================= }
  114.  
  115. { Routine: U_SetPreferences }
  116. { Purpose: Set new preferences, to be written out to the file }
  117.  
  118. procedure U_SetPreferences(thePrefsH:Handle);
  119. var
  120.  thePrefs:PrefsHRec;
  121.  
  122.  
  123. begin
  124. thePrefs := PrefsHRec(thePrefsH);
  125. thePrefs^^.FormatRevision := PrefsFormatRevision;    { Version number }
  126. thePrefs^^.theWindowLocRec := theWindowLocRec;        { Save the window location data }
  127.  
  128. { Use the form:   thePrefs^^.xxxx := xxxx;    }
  129. end;
  130.  
  131. { ======================================================= }
  132.  
  133. { Routine: Close_The_Input_File }
  134. { Purpose: Close the input file }
  135.  
  136. procedure Close_The_Input_File;
  137. var
  138.     ErrorCode:OSErr;
  139.  
  140.  
  141. begin
  142. ErrorCode := FSClose(Files.inputRefNum);                { Invalidate the refnum }
  143. Files.inputRefNum := 0;                                { Close the file }
  144. end;
  145.  
  146. { ======================================================= }
  147.  
  148. { Routine: Close_The_Output_File }
  149. { Purpose: Close the output file }
  150.  
  151. procedure Close_The_Output_File;
  152. var
  153.         ErrorCode:OSErr;
  154.  
  155.  
  156. begin
  157. ErrorCode := FSClose(Files.outputRefNum);            { Invalidate the refnum }
  158. Files.outputRefNum := 0;                                { Close the file }
  159. end;
  160.  
  161. { ======================================================= }
  162.  
  163. { Routine: Open_The_File }
  164. { Purpose: Open the input file }
  165.  
  166. procedure Open_The_File;
  167. var
  168.     NumberOfTypes,theVolRefNum:integer;
  169.     ErrorCode:OSErr;
  170.  
  171.  
  172. begin
  173. Files.typeList[0] := 'TEXT';                            { Open TEXT files }
  174. Files.typeList[1] := 'text';                            { Open other files }
  175. NumberOfTypes := 1;                                    { Only use first filetype in the list }
  176. if (Do_The_Open_File(NumberOfTypes,theVolRefNum,nil,nil)) then{ Try to open the file }
  177.     begin
  178.     ErrorCode := FSOpen(Files.inputFileName,Files.Reply.vRefNum,Files.inputRefNum);{ Open the file }
  179.     
  180.     { ADD in your code here to read the file }
  181.     
  182.     Close_The_Input_File;                            { Now close this file }
  183.     end;
  184. end;
  185.  
  186. { ======================================================= }
  187.  
  188. { Routine: Select_Volume }
  189. { Purpose: Select a volume }
  190.  
  191. procedure Select_Volume;
  192. var
  193.     theFile:FSSpec;
  194.  
  195.  
  196. begin
  197. if (Has.NewStdFile) then                                { Do this if we have new Standard File available }
  198.     begin
  199.     if (Do_The_Select_Volume(theFile)) then
  200.         begin
  201.         end;
  202.     end
  203. else
  204.     begin
  205.     end;
  206. end;
  207.  
  208. { ======================================================= }
  209.  
  210. { Routine: Save_The_File }
  211. { Purpose: Save the file }
  212.  
  213. procedure Save_The_File;
  214. var
  215.     theVolRefNum:integer;
  216.     theRefNum:integer;
  217.  
  218.  
  219. begin
  220. if (Do_The_Save_File('????','TEXT','Save as : ','Untitled ',theVolRefNum,theRefNum,nil)) then
  221.     begin
  222.  
  223.     { ADD in your code here to save the file }
  224.  
  225.     Close_The_Output_File;                        { Now close this file }
  226.     end;                                                { End of IF }
  227. end;
  228.  
  229. { ======================================================= }
  230.  
  231. { Routine: Print_The_Data }
  232. { Purpose: Print the data }
  233.  
  234. procedure Print_The_Data;
  235. var
  236.     ThePrintPort:GrafPtr;                                { Print port }
  237.     SavedPort:GrafPtr;                                    { saved window port }
  238.     Doing_Page:integer;                                    { Current print page number }
  239.     NumberOfCopies:integer;                                { Number of copies of each page }
  240.     Count:integer;                                        { Number of copies of each page }
  241.     Cancelled:Boolean;                                    { User cancelled flag }
  242.     NumberOfPages:integer;                                { Change this for the number of pages to do }
  243.     ThePageString:Str255;                                { For showing the page number }
  244.  
  245.  
  246. begin
  247. GetPort(SavedPort);                                { Get the current window port }
  248.  
  249. NumberOfPages := 2;                                    { CHANGE for your pages limit }
  250. OpenThePrinter(Cancelled);                            { Ask about the next page }
  251.  
  252. if ((Printing.pPrPort <> NIL) and (Printing.hPrint <> NIL) and (not(Cancelled))) then
  253.     begin
  254.     ThePrintPort := GrafPtr(Printing.pPrPort);        { Get the current window port }
  255.     SetPort(ThePrintPort);                            { Point to the printer port }
  256.     TextFont(systemFont);
  257.     TextSize(12);
  258.     Doing_Page := 1;
  259.  
  260.     repeat                                            { Do all the pages in our document }
  261.         InitCursor;
  262.         PrOpenPage(Printing.pPrPort, nil);            { Open a new page }
  263.         SetPort(ThePrintPort);
  264.  
  265.         { ADD YOUR PRINTING CODE HERE, DRAW INTO THIS PORT }
  266.         MoveTo(10, 20);
  267.         DrawString('Printing from Marksman ™code , page ');
  268.         NumToString(Doing_Page,ThePageString);
  269.         DrawString(ThePageString);
  270.         { END OF ADD YOUR PRINTING CODE HERE }
  271.  
  272.         PrClosePage(Printing.pPrPort);                { Print this page }
  273.         SetPort(SavedPort);
  274.         Doing_Page := Doing_Page + 1;                { Bump the page count }
  275.     until (Doing_Page > NumberOfPages);
  276.     end;
  277.  
  278. CloseThePrinter;                                    { Close the printer }
  279. SetPort(SavedPort);
  280. InitCursor;
  281. end;
  282.  
  283. { ======================================================= }
  284. { ======================================================= }
  285. end.
  286.